<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
     <meta name="format-detection" content="telephone=no">
    <meta name="viewport" content="minimal-ui,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <title>购物车-{$webseting.web_title}</title>
    <link href="__PUBLIC__/wap/css/rest.css"  rel="stylesheet">
    <link href="__PUBLIC__/wap/css/product.css"  rel="stylesheet">
     <link href="__PUBLIC__/wap/css/user.css"  rel="stylesheet">
     
</head>
<body>
     <!--绑定头部-->    
 <include file="Public/binding_head"/>
    <!--绑定头部-->
    <header id="header" class="u-header clearfix">
        <div class="u-hd-left f-left">
            <a href="javascript:history.go(-1);" class="J_backToPrev"><span class="u-icon-px i-hd-back"></span></a>
        </div>
        <div class="u-hd-tit"><span>购物车</span></div>
    </header>

    <div class="layout_body">
        <div class="touchweb_page-shopCart">
            <div class="goods_box">

            <volist name="list['goods_list']" id="vo">
                <div class="goods_box-body cart_{$vo.rec_id}" >
                    <div class="product_list">
                        <div class="product_list_wrap">
                            <input type="checkbox" class="check_box cart_chk cart_chk_{$vo.rec_id}" name="cart_chk" data="{$vo.rec_id}" checked="">
                            <div class="product_content">
                                <div class="product_box">
                                    <div class="product_pic" data-tpa="GOTO_PRODUCT_DETAIL">
                                        <img   data-tpa="GOTO_PRODUCT_DETAIL" src="{:U('wap/index/get_thumbs',array('auto'=>65))}?img={$vo.goods_img}">
                                    </div>
                                    <a class="product_con" href="{:U('wap/goods/goods_detail',array('id'=>$vo['goods_id']))}">
                                        <span class="product_title">
                                       <if condition="$vo['rec_type'] eq 1">
                                          【限时抢购】
                                       </if>
                                        {$vo.goods_name}  {$vo.goods_attr}
                                        <p class="cell_price">
                                            <span class="sale_price">
                                            ¥{$vo.goods_price}
                                             <s class="s_price" style="">¥{$vo.market_price}</s>
                                            </span>
                                        </p>
                                    </a>
                                    <div class="product_option">
                                        <div class="tool_num">
     <section class="select" style="display: inline-block;">
        <!-- <p class="label">数量</p> -->
        <p class="option" style="margin-left: 0px;">
            <input type="hidden" class="good_price_{$vo.rec_id}" size="4" value="{$vo.goods_price}" name="good_price" data="{$vo.rec_id}">
             <if condition="$vo['rec_type'] eq 1">
             
            <!--  <a class="btn-del  save_good_{$vo.rec_id}" data="{$vo.rec_id}"  style="background-position: 9px -20px;" href="javascript:void(0);">-</a>
                        <input type="text" data="{$data.rec_id}" name="good_num" class="fm-txt good_num good_num_{$vo.rec_id}" value="{$vo.goods_number}" readonly="readonly">
                        <a class="btn-add  add_good_{$vo.rec_id}" data="{$vo.rec_id}" href="javascript:void(0);">+</a>
             -->
              <a class="btn-del save_good save_good_{$vo.rec_id}" data="{$vo.rec_id}"  style="background-position: 9px -20px;" href="javascript:void(0);">-</a>
            <input type="text" data="{$data.rec_id}" name="good_num" class="fm-txt good_num good_num_{$vo.rec_id}" value="{$vo.goods_number}" readonly="readonly">
            <a class="btn-add add_good add_good_{$vo.rec_id}" data="{$vo.rec_id}" href="javascript:void(0);">+</a>
             
             <else/>                         
            
            <a class="btn-del save_good save_good_{$vo.rec_id}" data="{$vo.rec_id}"  style="background-position: 9px -20px;" href="javascript:void(0);">-</a>
            <input type="text" data="{$data.rec_id}" name="good_num" class="fm-txt good_num good_num_{$vo.rec_id}" value="{$vo.goods_number}" readonly="readonly">
            <a class="btn-add add_good add_good_{$vo.rec_id}" data="{$vo.rec_id}" href="javascript:void(0);">+</a>
             
             </if>
        </p>
    </section>

                                         
                                        </div>

                                        <div class="wastebin-container del_good del_good_{$vo.rec_id}" data="{$vo.rec_id}" >
                                            <div class="wastebin">
                                                <i class="wastebin-up"></i>
                                                <i class="wastebin-down"></i>
                                            </div>
                                        </div>

                                       
                                    </div> </div>
                            </div>
                        </div>
                    </div>
                </div>
     </volist>

               
            </div>
        </div>
    </div>


<if condition="!empty($discount) && !empty($list['goods_list'])">
    <div class="new-addr">
           <p class="new-tit new-p-re" style="font-size: 14px;">
                      <span class="new-txt consignee">使用折扣：</span>
            </p>
        <volist name="discount" id="vo">
             <li class="new-mu_l2 " data="0">
                <p class="new-tit new-p-re" style="font-size: 14px;border:none;">
                    <input id="discount_{$vo.id}" name="discount_val" type="checkbox" value="{$vo.id}"  data="{$vo.discount}" >
                     <label for="discount_{$vo.id}">{$vo.type_name}折扣{$vo.discount_val}</label>
                </p>
           </li>
       </volist>
         </div>
</if>
 <div style="height:103px;">
   </div>
    <div class="layout_footer">
        <div class="normal">
            <label class="all_check" checked="true">
                <input type="checkbox" class="all_check check_box all_check_c" checked="true">
                <br>
                <span>
                全选
                </span>
            </label>
            <div class="checkout_info">
               <span>
                    <span class="price all_price">¥{$list.need_pay}</span>
                    <br>
                    <em>应付价</em>
                </span>
                  <span class="plus discount_price" style="padding:0;">/</span>
                <span class="discount_price">
                   <span class="price"><s class="all_old_price" style="text-decoration: line-through; color:#999;">¥{$list.need_pay}</s></span>
                   <br>
                   <em>总价</em>
                                </span>
               
                
               <!--  <span class="plus">+</span>
               <span>
                   <span class="price">¥ 0</span>
                   <br>
                   <em>运费</em>
               </span> -->
            </div>
            <a onclick="javascript:void(0);" data-tpa="GOTO_CHECKOUT" class="btn_checkout go_pay">
                结算(<span class="all_num">{$list.all_num}</span>)
            </a>
        </div>
       <!--  <div class="edit">
           <label class="all_check" checked="true">
               <input type="checkbox" class="check_box all_check" checked="true">
               <span>
               全选
               </span>
           </label>
           <a href="javascript:;" class="btn_del">
               删除
           </a>
       </div> -->
    </div>
  <!--end top-->
   <include file="Public/footer" />
    <!--end 页脚-->
   <input type="hidden" name="cart_id" value="{$list.cart_id}"/>
   <input type="hidden" name="discount" value="0"/>
   
 <include file="Public/wap_javascript" />
 <!--微信分享-->    
 <include file="Public/share_weixin" />

 <script type="text/javascript">
   var  binding_is_check=0;// 重复再次弹出 1是 0否
   var  binding_page='cart';// //当前页面名称 不可重复
</script>  
         <!--绑定-->    
 <include file="Public/binding_phone"/>
    <!--绑定-->

<script type="text/javascript">
   $(function(){
    $('.all_check_c').click(function(){
        if ($(".all_check_c").prop("checked")) {  
            $(":checkbox").prop("checked", true);  
        } else {  
            $(":checkbox").prop("checked", false);  
        }
        //计算商品价格  
         get_goods_price();  
    });
     $('.cart_chk').click(function(){
        var __this=$(this);
        if (__this.prop("checked")) { 
                var chk=1; 
               $(".cart_chk").each(function(){
                    if(!$(this).prop("checked")){
                      chk=0;
                    }
                });
               if(chk){
                $('.all_check_c').prop("checked", true);  
               }
        } else { 
            $('.all_check_c').prop("checked", false);  
        }
        //计算商品价格  
         get_goods_price();  
    });
    //增加数量
     $(".add_good").click(function(){
        var _this_add=$(this);
         var good_id=_this_add.attr('data');

          var _this_save=$(".save_good_"+good_id);
          var _this_del=$(".del_good_"+good_id);
          var _this_num=$(".good_num_"+good_id);
          var goods_num=_this_num.val();
          goods_num++;
          _this_num.val(goods_num);
          $.ajax({ 
            url: "{:U('wap/cart/save_cart')}",
            type:'get',
            data: {rec_id:good_id,goods_num:goods_num},
            dataType: 'json',
            success: function(data){
              if(data.status==1){
                //计算商品价格 
                 get_goods_price();
              }else{
                 goods_num--;
                _this_num.val(goods_num);
                 //alert(data.error)
                     layer.msg(data.error, {icon: 5}); 
              }
            }
           }); 
        
     });
     //减少数量
     $(".save_good").click(function(){
        var _this_save=$(this);
         var good_id=_this_save.attr('data');
          var _this_num=$(".good_num_"+good_id);
          var goods_num=_this_num.val();
          goods_num--;
          if(goods_num<=0){
            goods_num=1;
            _this_num.val(1);
          }else{
             _this_num.val(goods_num);
          }
           $.ajax({ 
            url: "{:U('wap/cart/save_cart')}",
            type:'get',
            data: {rec_id:good_id,goods_num:goods_num},
            dataType: 'json',
            success: function(data){
              if(data.status==1){
                //计算商品价格 
                 get_goods_price();
              }else{
                 goods_num++;
                _this_num.val(goods_num);
                 //alert(data.error)
                  layer.msg(data.error, {icon: 5}); 
              }
            }
           }); 
          //计算商品价格  
     }); 
     //删除数量
     $(".del_good").click(function(){
          var _this_del=$(this);
          var good_id=_this_del.attr('data');
           $.ajax({ 
            url: "{:U('wap/cart/del_cat')}",
            type:'get',
            data: {rec_id:good_id},
            dataType: 'json',
            success: function(data){
              if(data.status==1){
                 $('.cart_'+good_id).remove();
                //计算商品价格 
                 get_goods_price();
              }else{
                //alert(data.error)
                layer.msg(data.error, {icon: 5}); 
              }
            }
           }); 
         
     }); 

    $(".go_pay").click(function(){
          var all_num=$(".all_num").html();
          all_num=parseInt(all_num);
          if(all_num>0){
            var cart_id=$("input[name='cart_id']").val();
            var discount=$('input[name="discount"]').val();
            var url="<?php echo U('Wap/cart/order_add'); ?>?cart_id="+cart_id+'&discount='+discount;
            window.location.href=url;
          }
     }); 

   }); 
 //计算商品价格  
function get_goods_price(){
    var discount_consume=$('input[name="discount_consume"]').val();
    discount_consume=parseFloat(discount_consume);
    if(discount_consume<=0){
        discount_consume=1;
    }
    var total=parseFloat(0);
    var all_num=0;
    var goods_id_str='';
    $(".cart_chk").each(function(){
        var __this=$(this);
        if(__this.prop("checked")){
            var goods_id=__this.attr('data');
            var num=$('.good_num_'+goods_id).val();
            num=parseInt(num);
            var good_price=$(".good_price_"+goods_id).val();
            good_price=parseFloat(good_price);
            total=total+good_price*num;
            goods_id_str=goods_id_str+','+goods_id;
            all_num=all_num+num;
        }
    });
    if(goods_id_str){
        goods_id_str=goods_id_str.substr(1);
    }
    if(total>0){
        $('.go_pay').removeAttr('style');
    }else{
        $('.go_pay').css('cssText','background-color:rgb(171, 168, 168) !important;');
    }
    total=total.toFixed(2);
    var discount=get_discount();//折扣
    if(discount){
       $('.all_old_price').html('¥'+total);
       $('.discount_price').show();
        discount=parseFloat(discount);
        total=total*discount;
        total=total.toFixed(2);
    }else{
      $('.discount_price').hide();
    }
    $('.all_price').html('¥'+total);
    $('input[name="cart_id"]').val(goods_id_str);
    $('.all_num').html(all_num);
}
function get_discount(){
    _this=$('input[name="discount_val"]:checked');
   if(_this.length){
    $('input[name="discount"]').val(_this.val());
     return  _this.attr('data');
   }else{
     $('input[name="discount"]').val(0);
    return 0;
   }
}

$(function(){
  get_goods_price();
  $('input[name="discount_val"]').change(function(){
    var _this=$(this);
    var check=_this.prop('checked');
    if(check){
      $('input[name="discount_val"]').prop('checked',false);
      _this.prop('checked',true);
    }
    get_goods_price();
  });
});
</script>    
</body>
</html>